<?php

class DB {

    static $_connection;

    public static function getDBConnection() {
        if (!isset(self::$_connection)) {
            self::$_connection = mysql_connect(DB_HOST . ":" . DB_PORT, DB_USER, DB_PASS) or die(mysql_error());
            mysql_select_db(DB_NAME, self::$_connection);
        }
        return self::$_connection;
    }

    public static function escape($string) {
        return mysql_real_escape_string($string);
    }

    public static function escapeArr($arr) {
        if (empty($arr))
            return $arr;
        foreach ($arr as $key => $value) {
            $arr[$key] = $this->escape($value);
        }
        return $arr;
    }

}